package com.victor.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.victor.entity.Bybookcoupon;
import com.victor.entity.Mybybookcoupon;

@Mapper
public interface BybookcouponDao {

	// 查询购书卷
	@Select({ "select * from bybookcoupon where id != 1" })
	List<Bybookcoupon> getBybookcouponList();

	// 添加购书卷
	@Insert({ "insert into bybookcoupon (money,valid_start,valid_end,number,former_number,already_number,remarks) values (#{money},#{valid_start},#{valid_end},#{number},#{number},'0',remarks)" })
	int addBybookcoupon(Bybookcoupon bybookcoupon);

	// 批量删除
	int batchDelete(@Param("ids") int[] ids);

	// 获取我的购书卷
	List<Mybybookcoupon> getmybybookcoupon(@Param("userid") String userid);

	// 获取我的购书卷表所有购书卷
	List<Mybybookcoupon> getAllmybybookcoupon();

	// 使购书卷失效
	@Update({ "update mybybookcoupon set flag='3' where id=#{mbid}" })
	int updateShixiao(@Param("mbid") int mbid);

	// 查询八元购书券
	@Select({ "select * from bybookcoupon where id=1" })
	Bybookcoupon selBybookcoupon();

	// 查询所有购书券
	@Select({ "select * from bybookcoupon where number>=1" })
	List<Bybookcoupon> selBybookcouponAll();

	@Update({ "UPDATE bybookcoupon set number=#{number},already_number=#{newAlready_number} where id=#{id}" })
	boolean updBybookcouponById(@Param("id") int id, @Param("number") int number, @Param("newAlready_number") int newAlready_number);

	Mybybookcoupon findById(@Param("id") String id);

	@Update({ "UPDATE mybybookcoupon SET flag = #{flag} WHERE id = #{id}" })
	int updateCouponFlag(@Param("id") String couponid, @Param("flag") String flag);

}
